package com.pym.service.impl;

import com.pym.dao.PymUploadPhotoDao;
import com.pym.dao.PymWpgjDao;
import com.pym.dao.PymWpxxDao;
import com.pym.entity.PymUploadPhoto;
import com.pym.entity.Wpgj;
import com.pym.entity.PymWpxx;
import com.pym.service.PymWpdjService;
import com.pym.util.pymUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName
 * @Description TODO
 * @Author wmj
 * @Date 2021/8/21
 * @Version 1.0
 **/

@Service
public class PymWpdjServiceImpl implements PymWpdjService {

    @Autowired
    private PymWpxxDao pymWpxxDao;

    @Autowired
    private PymUploadPhotoDao pymUploadPhotoDao;

    @Autowired
    private PymWpgjDao pymWpgjDao;

    @Override
    public int wpdjService(PymWpxx pymWpxx, String czrName, String czrIdCard, String domain, String path) {

        pymWpxx.setId(pymUtil.generateUUID());
        pymWpxx.setWpzt("1");
        pymWpxx.setWpbh(pymUtil.generateUUID());

        int i = pymWpxxDao.insert(pymWpxx);
        if(i > 0){
            Wpgj wpgj = new Wpgj();
            wpgj.setId(pymUtil.generateUUID());
            wpgj.setWpId(pymWpxx.getId());
            wpgj.setWpbh(pymWpxx.getWpbh());
            wpgj.setType("6");
            wpgj.setCzrIdCard(czrIdCard);
            wpgj.setCznr("登记成功！！");
            wpgj.setCzrName(czrName);
            wpgj.setOrgCode("440300000000");
            wpgj.setOrgName("深圳市公安局南山分局");
            wpgj.setIsDel("0");
            pymWpgjDao.insert(wpgj);

            PymUploadPhoto pymUploadPhoto = new PymUploadPhoto();
            pymUploadPhoto.setId(pymUtil.generateUUID());
            pymUploadPhoto.setBusinessId(pymWpxx.getId());
            pymUploadPhoto.setDomain(domain);
            pymUploadPhoto.setPath(path);
            pymUploadPhoto.setBusinessType("01");
            pymUploadPhoto.setIsDel("0");
            //设置照片开始截取的位置
            int start = path.lastIndexOf("/") + 1;
            pymUploadPhoto.setName(path.substring(start));
            pymUploadPhoto.setAddUser(pymWpxx.getAddUser());
            pymUploadPhoto.setFileSize("500");
            pymUploadPhotoDao.insert((pymUploadPhoto));
            return 1;
        }
        return 0;
    }
}
